package com.ks.controller;

import com.ks.common.PageResult;
import com.ks.common.Result;
import com.ks.dto.PageQueryDTO;
import com.ks.entity.Indicator;
import com.ks.service.IndicatorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/indicator")
@Slf4j
public class IndicatorController {


    @Autowired
    private IndicatorService indicatorService;

    //分页查询指标列表
    @PostMapping("/list")
    public Result<PageResult> list(@RequestBody PageQueryDTO pageQueryDTO) {
//        log.info("分页查询指标列表:{}", pageQueryDTO);
        PageResult pageResult = indicatorService.pageIndicator(pageQueryDTO);
        return Result.success(pageResult);
    }

    //新增指标
    @PostMapping
    public Result add(@RequestBody Indicator indicator) {
        log.info("新增指标:{}", indicator);
        indicatorService.addIndicator(indicator);
        return Result.success();
    }

    //修改指标
    @PutMapping
    public Result update(@RequestBody Indicator indicator) {
        log.info("修改指标:{}", indicator);
        indicatorService.updateIndicator(indicator);
        return Result.success();
    }

    //删除指标
    @DeleteMapping({ "/{id}"})
    public Result delete(@PathVariable("id") Integer id) {
        log.info("删除指标:{}", id);
        indicatorService.deleteIndicator(id);
        return Result.success();
    }

    //获取指标名称列表
    @GetMapping("/nameList")
    public Result<String[]> nameList() {
        log.info("获取指标名称列表");
        String[] nameList = indicatorService.getNameList();
        return Result.success(nameList);
    }
}
